class UsersController < ApplicationController
  before_filter :authenticate_user!

  # GET /users
  def list
  end

  # GET /users/me
  def me
    @user = current_user
  end

  # PUT /users/me
  def update
    @user = current_user
    @user.update_attributes(params[:user])
    respond_to do |format|
      format.html { redirect_to users_list_path }
    end
  end

  # GET /users/me/:setting
  def setting
    render action: "list" unless params[:setting] == 'auth'
    @user = User.find(current_user.id)
  end

  # PUT /users/me/:setting
  def update_setting
    if params[:setting] == 'auth'
      render action: "list"
    else
      @user = User.find(current_user.id)
      if @user.update_with_password(params[:user])
        sign_in @user, :bypass => true
        # redirect_to users_list_path
        render "users/setting", setting: 'auth', locals:{success: true}
      else
        render action: "setting", setting: 'auth'
      end
    end
  end
end
